/*================================================================
*   Copyright (C) 2021 IMVS Ltd. All rights reserved.
*   
*   Filename   ：cantool.h
*   Creator    ：Chase Wu
*   Create Date：2021/06/04
*   Description：
*
================================================================*/


#ifndef _CAN_TOOL_H
#define _CAN_TOOL_H
#ifdef __cplusplus
extern "C"
{
#endif

#include <net/if.h>
#include <linux/can.h>
#include <linux/can/raw.h>

enum CANTOOL_MODE{
    CANTOOL_RECV_MODE,
    CANTOOL_SEND_MODE,
};

typedef struct cantool cantool_t;

typedef struct {
    int (*init)(cantool_t*);
    int (*release)(cantool_t*);

    int (*send)(cantool_t*);
    int (*receive)(cantool_t*);
}cantool_op_t;

struct cantool{
    int cansocket;
    struct sockaddr_can addr;
	struct ifreq ifr;

    struct can_frame frame;
    struct can_filter rfilter[1];

    char *dev;

    cantool_op_t* op;
};

int cantool_destory(cantool_t *cantool);
int cantool_create(cantool_t **pcantool, char *dev);

int cantool_process(char *dev, int mode);

#ifdef __cplusplus
}
#endif
#endif //_CAN_TOOL_H
